/*
 */

package presentacion.comun;



import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseMotionAdapter;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;


/**
 * GlassPanel usado en todas las TaskWorkers
 * 
 * @author Calderas
 */
public class GlassPanel extends JComponent  {
    private Image image=null;
    private Icon icon;
    private Boolean imagen=false;

    public GlassPanel(Boolean imagen) {
        this();
        image=null;
    }
    
    
    
    public GlassPanel() {
        this.setVisible(false);
        addMouseListener(new MouseAdapter() { });
        addMouseMotionListener(new MouseMotionAdapter() { });
        addKeyListener(new KeyAdapter() { });
        setFocusTraversalKeysEnabled(false);
        addComponentListener(new ComponentAdapter() {
            @Override
            public void componentShown(ComponentEvent evt) {
                requestFocusInWindow();
            }
        });
        //System.out.println(getClass().getResource("/presentacion/recursos/rectoria.png"));
        // this.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentacion/recursos/rectoria.png")));
        //setBackground(new Color(112,17,107));
       setBackground(Color.BLACK);
      
       //setBackground(Color.WHITE);
    }

    @Override
    protected void paintComponent(Graphics g) {
        Dimension frameSize = this.getParent().getSize();   
        Graphics2D g2 = (Graphics2D) g;
       
       
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        
        Rectangle clip = g.getClipBounds();

        AlphaComposite alpha = AlphaComposite.SrcOver.derive(0.45f);
        Composite composite = g2.getComposite();
        g2.setComposite(alpha);
        
        g2.setColor(getBackground());
        g2.fillRect(clip.x, clip.y, clip.width, clip.height);
        
        if(image!=null ) 
            g2.drawImage(image, (frameSize.width-image.getWidth(this))/2 , (frameSize.height-image.getHeight(this))/2 , 372, 515, null);
        g2.setComposite(composite);
         
    }
    
       public Icon getIcon() {
        return icon;
    }

    public void setIcon(Icon icon){
        this.icon=icon;
        if(icon!=null)
            image=((ImageIcon)icon).getImage();
    }
}
